package de.homelabs.bookstore.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import de.homelabs.bookstore.domain.Category;
import de.homelabs.bookstore.web.ui.HLMenuManager;
import de.homelabs.bookstore.web.ui.MenuEntry;

@Controller("aboutController")
public class AboutController {

	@Autowired
	@Qualifier("hlMenuManager")
	private HLMenuManager hlMenuManager;
	
	@RequestMapping("/modul/about.htm")
	public ModelAndView indexHandler(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		//buffer for parsed content
		StringBuffer content = new StringBuffer();
				
		Map<String, Object> defaultModel = new HashMap<String, Object>();
		defaultModel.put("categoryList", new ArrayList<Category>());
		
		/*
		 * Start: mainMenu
		 */
		List<MenuEntry> mainMenu = hlMenuManager.getMainMenuEntries();
		//into main model map
		defaultModel.put("menuEntries", mainMenu);
		/*
		 * End: mainMenu
		 */
		
		/*
		 * testcontent
		 */
		content.append("<p><h1>About</h1></p>");
		content.append("<p>Hier ist die About Seite</p>");
		defaultModel.put("content",content.toString());
		
		//FreeMarkerCascadedView
		return new ModelAndView("test.ftl", defaultModel);
				
	}
}
